package close.mazegame.entity;

import box2dLight.PointLight;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import close.mazegame.art.MiscArt;
import close.mazegame.collision.Collidable;
import close.mazegame.entity.player.Player;
import close.mazegame.level.MazeLevel;

public class EndStone extends PhysicsEntity implements Collidable {
	
	private static final float LIGHT_BRIGHTNESS = 0.7f;
	
	private PointLight pl;

	public EndStone(Vector2 pos, MazeLevel level) {
		super(level);
		this.mainTexture = MiscArt.endStone;
		
		BodyDef bodyDef = new BodyDef();
		bodyDef.type = BodyType.StaticBody;
		bodyDef.position.set(pos);
		body = level.getWorld().createBody(bodyDef);
		
		PolygonShape poly = new PolygonShape();
		poly.setAsBox(this.getXSize()/2, this.getYSize()/2);
		FixtureDef fixtureDef = new FixtureDef();
		fixtureDef.filter.maskBits = EntityCategory.PLAYER.getBits();
		fixtureDef.isSensor = true;
		fixtureDef.shape = poly;
		fixtureDef.density = 4.0f;
		fixtureDef.friction = 0.0f;
		fixtureDef.restitution = 0.1f;

		body.createFixture(fixtureDef);
		
		body.setUserData(this);
		
		poly.dispose();
		
		pl = level.addPointLight(body, 64,  new Color(1.0f, 1.0f, 1.0f, LIGHT_BRIGHTNESS), 10.0f, 0);
		pl.setActive(false);
	}

	@Override
	public float getXSize() {
		return 0.6f;
	}
	
	@Override
	public float getYSize() {
		return 0.6f;
	}

	@Override
	public void update(float delta) {
	}

	@Override
	public void startContact(Collidable other) {
		if(other instanceof Player){
			pl.setActive(true);
		}
	}
	
	public void dispose(){
		super.dispose();
		pl.remove();
	}

	@Override
	public void endContact(Collidable other) {
	}

}
